package com.example.my.shop.mybatis.controller;

import com.example.my.shop.mybatis.service.Imp.TbUserServiceImpl;
import com.example.my.shop.mybatis.service.TbUserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/deleteUser")
public class DeleteUserController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        TbUserService tbUserService = new TbUserServiceImpl();
        int i = tbUserService.deleteUserBuId(Integer.parseInt(id));

        req.setAttribute("message", i > 0 ? "delete successful" : "delete fail");;
        req.getRequestDispatcher("/getUsers").forward(req, resp);
    }
}
